<?php


namespace app\helpers;


class BinHelper {

    public static function run($action, $num = null) {
        $R_IP = defined('R_IP') ? R_IP : '';
        $L_IP = defined('L_IP') ? L_IP : '';
        $binFile = BIN_FILE;
        $s = '';
        if(null !== $num){
            $s = " -s {$num}";
        }
        $cmd = DATA_ROOT . "/bin/{$binFile} -c {$action}{$s} -r {$R_IP} -l {$L_IP}";
        \Yii::warning($cmd, 'cmd');
        try {
            $output = [];
            exec($cmd, $output);
            \Yii::warning(print_r($output, true), 'cmd');
        } catch (\Exception $e) {
            \Yii::warning($e->getMessage(), 'cmd');
        }
        return $output;
    }
}